﻿using System;
using System.Linq;

namespace IOPvsOOP.Null.NOIF
{
    public enum Cluster
    {
        Director,
        Executive,
        Manager,
        Leader,
        OfficeWorker
    }

    public class Employee
    {
        public string Name { get; set; }
        public string Last { get; set; }
        public string Number { get; set; } 
        public Cluster Cluster { get; set; }
    }

    public interface IPerformer<out T>
    {
        void Ask(Action<T> action);
    }

    public class Performer<T> : IPerformer<T>
    {
        private readonly T value;

        public Performer(T value)
        {
            this.value = value;
        }

        public void Ask(Action<T> action)
        {
            action(value);
        }
    }

    public class NoPerformer<T> : IPerformer<T>
    {
        public void Ask(Action<T> action) { }
    }

    public class EmployeeRepositoryNullNOIF
    {
        private readonly Employee[] repository =
        {
            new Employee {Name = "Claudio", Last = "Pattarello", Cluster = Cluster.Manager, Number = "CLAPAT01"},
            new Employee {Name = "Andrea", Last = "Chiarini", Cluster = Cluster.Leader, Number = "ANDCHI01"},
            new Employee {Name = "Matteo", Last = "Baglini", Cluster = Cluster.Leader, Number = "MATBAG01"},
        };

        public IPerformer<Employee> Get(string number)
        {
            var employee = repository.SingleOrDefault(e => e.Number == number);
            if (employee==null)
                return new NoPerformer<Employee>();
            return new Performer<Employee>(employee);
        }
    }
}